package com.baosight.sczx.zm.ci.service;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.ci.domain.ZMCITernateInfo;
/**
 * 三违信息
 */
public class ServiceZMCI40 extends ServiceEPBase {
	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p> 
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cp.department", "orgCode", "orgName", false));
		outInfo.set("fdCreatorId", UserSession.getUserId());//登录人的默认值
		outInfo.set("fdCreator", UserSession.getInSessionProperty("UserCname"));
		outInfo.set("fdCreateDepartmentId", UserSession.getInSessionProperty("orgCode"));//单位的默认值		
		outInfo.set("fdCreateDepartment", UserSession.getInSessionProperty("orgName"));//单位的默认值
		return outInfo;
	}
	/**
	 * <p>Function: query</p>
	 * <p>Description: 查询</p> 
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		//获取登录人信息
		String miningcode = (String) UserSession.getInSessionProperty("miningCode");//c.102
		String fdName =(String) UserSession.getInSessionProperty("miningName");//矿名称
		if(fdName!=null&&!"".equals(fdName))
		{
		if(fdName.indexOf("打通一矿") > 0 ){
			fdName = "打通一矿";
		}
		else if(fdName.indexOf("松藻煤矿") > 0 ){
			fdName = "松藻煤矿";
		}
		else if(fdName.indexOf("渝阳煤矿") > 0 ){
			fdName = "渝阳煤矿";
		}
		else if(fdName.indexOf("石壕煤矿") > 0 ){
			fdName = "石壕煤矿";
		}
		else if(fdName.indexOf("逢春煤矿") > 0 ){
			fdName = "逢春煤矿";
		}
		}
		StaticTools.setQueryParameters(inInfo, "fdName", fdName, true);
		/*if(miningcode!="C.102"){
		//获取矿名称过滤信息
			//对打通一矿做处理 -- 松藻煤电公司打通一矿
			if(fdName.length()>4) fdName = fdName.substring(6);
			//作为参数封装进inInfo中
			
		}*/
		//获取前台日期值
		String date = inInfo.getString("querydate");
		//判断日期是否为空
		if(date == null || date.trim().equals("")){
			//传入当前日期
			date = StaticTools.getDate();
			//设置进EiInfo中
			inInfo.set("querydate", date);
		}
		//日期存在传入xml查询 -作为调度日期
		StaticTools.setQueryParameters(inInfo, "fdVirtualDate", date, false);
		//返回EiInfo结果集
		EiInfo outInfo = super.query(inInfo, "ZMCITernateInfo.query", new ZMCITernateInfo());
		return outInfo;
	}	
	
	/**
	 * <p>Function: insert</p>
	 * <p>Description: 新增</p> 
	 */
	@Override	
	public EiInfo insert(EiInfo inInfo) {
		EiInfo outinfo = new EiInfo();
		ZMCITernateInfo _dom = new ZMCITernateInfo();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();

		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			this.dao.insert("ZMCITernateInfo.insert", _dom);
		}
		outinfo = this.query(inInfo);
		outinfo.setStatus(1);
		outinfo.setMsg("操作" + rowcount + "记录成功");
		return outinfo;
	}
	 
	/**
	 * <p>Function: update</p>
	 * <p>Description: 修改</p> 
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		ZMCITernateInfo _dom = new ZMCITernateInfo();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			this.dao.update("ZMCITernateInfo.update", _dom);
		}
		outInfo = this.query(inInfo);
		outInfo.setStatus(1);
		outInfo.setMsg("操作" + rowcount + "记录成功");
		return outInfo;
	}	
	/**
	 * <p>Function: delete</p>
	 * <p>Description: 删除</p> 
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		ZMCITernateInfo _dom = new ZMCITernateInfo();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			this.dao.delete("ZMCITernateInfo.delete", _dom);
		}
		outInfo = this.query(inInfo);
		outInfo.setStatus(1);
		outInfo.setMsg("操作" + rowcount + "记录成功");
		return outInfo;
	}	 
} 